
#ifndef SX_QVIEWPORT_FRAME_H
#define SX_QVIEWPORT_FRAME_H

#include <QWidget>
#include <sxViewportController.h>
#include <sxColor3.h>
#include <sxColor4.h>

using Sx::Interface::ViewportController;
using Sx::Graphics::Color3f;
using Sx::Graphics::Color4f;

class QToolBar;
class QToolButton;

namespace Sx {
namespace QtInterface {

class QViewport;

class QViewportFrame : public QWidget {
	Q_OBJECT

public:
	QViewportFrame(QWidget* parent, QViewport* viewport, const std::shared_ptr<ViewportController>& controller = nullptr, Qt::WFlags flags = 0);
	virtual ~QViewportFrame();

	virtual bool constructToolbar() = 0;

	bool update();
	bool update(float dt);
	bool reRender() const;
	bool updateAndRender();

	bool setController(const std::shared_ptr<ViewportController>& controller);
	std::shared_ptr<ViewportController> getController() const;

	void setToolBarHeight(unsigned int height);
	void setToolBarIconSize(unsigned int size);

	unsigned int getToolBarHeight() const;
	unsigned int getToolBarIconSize() const;

	/* Viewport Interface */
	bool setClearColor(const Color3f& color);
	bool setClearColor(const Color4f& color);
	bool setClearColor(float r, float g, float b);
	bool setClearColor(float r, float g, float b, float a);

	virtual void setRealtime(bool realtime = true);
	bool isRealtime() const;

	void setWarpCursor(bool warp);
	bool hasCursorWarp() const;

	virtual bool setFramesPerSecond(unsigned int fps);
	unsigned int getFramesPerSecond() const;

	/* Qt Events */
	void resizeEvent(QResizeEvent* e);
	void focusInEvent(QFocusEvent* e);

signals:
	void gainsFocus(QViewportFrame* viewport);

protected:
	/* POINTER_ONWERSHIP: NO (Qt handles the memory) */
	QViewport* viewport;

	/*
	 * Toolbar interface that allows the user to change the properties of
	 * the Viewport this ViewportFrame displays.
	 *
	 * POINTER OWNERSHIP: YES
	 */
	 QToolBar* toolbar;

	 /* Dimensions of the toolbar and its buttons */
	 unsigned int toolbarHeight;
	 unsigned int toolbarIconSize;

	/*
	 * This function provides a helper utility for the initialize function. This
	 * function provides a short-cut for defining a new button object for the
	 * provided toolbar.
	 */
	static bool ConstructToolButton(QToolButton*& button, QToolBar* toolBar, QWidget* parent, const char* objectName, const char* toolTip, const char* slot);
};

}

}

#endif
